<template>
  <component
    :width="width"
    :is="componentId"
    :title="title ? title : appDetail && appDetail[appId] ? '编辑' : '新增'"
    v-model="appShowDetail"
    :before-close="appHandleClose"
  >
    <div :class="pageClass">
      <div class="app-edit-main">
        <jax-form ref="appForm" v-model="appDetail" :json="json" @submit="appHandleSubmit" v-bind="formProps">
          <template v-for="slotName in Object.keys($slots)" v-slot:[slotName]="item">
            <slot :name="slotName" v-bind="{ item, appDetail }"></slot>
          </template>
          <slot></slot>
        </jax-form>
      </div>

      <slot name="footer">
        <div class="app-edit-footer" v-if="type == 'drawer'">
          <el-button :disabled="appSaving" @click="appHandleClose">取 消</el-button>
          <el-button :disabled="appSaving" type="primary" @click="appHandleSubmit">确 定</el-button>
        </div>
      </slot>
    </div>

    <template #footer v-if="type == 'dialog'">
      <el-button :disabled="appSaving" @click="appHandleClose">取 消</el-button>
      <el-button :disabled="appSaving" type="primary" @click="appHandleSubmit">确 定</el-button>
    </template>
  </component>
</template>

<script>
import pageDialogMixin from '../mixins/dialog-edit'

export default {
  name: 'AppDialogEdit',
  mixins: [pageDialogMixin],
  components: {},
  props: {
    type: {
      type: String,
      default: 'dialog',
    },
    full: {
      type: Boolean,
      default: true,
    },
    width: {
      type: String,
      default: '600px',
    },
    formProps: {
      type: Object,
      default: null,
    },
    title: {
      type: String,
      default: '',
    },
  },
  data() {
    return {}
  },
  created() {},
  computed: {
    componentId() {
      const { type } = this

      const components = {
        dialog: 'el-dialog',
        drawer: 'el-drawer',
      }

      return components[type] || 'el-dialog'
    },
    pageClass() {
      const { type } = this

      let pageClass = {
        [`app-${type}`]: true,
      }

      if (type == 'drawer') {
        if (this.full) pageClass['app-edit-full'] = true
      }

      return pageClass
    },
  },
  watch() {},
  created() {},
  methods: {},
}
</script>

<style lang="scss" scoped></style>
